﻿using System.Text;
using System.Xml.Linq;
using SPQueryToSql.Extensions;

namespace SPQueryToSql.ApplicationObjects.CAML
{
    internal class ViewAttributes
    {
        public string Scope;
        public string ModerationType;

        public ViewAttributes(XElement element)
        {
            Scope = element.AttributeValueString("Scope", string.Empty);
            ModerationType = element.AttributeValueString("ModerationType", string.Empty);
        }

        public override string ToString()
        {
            return ToString(0);
        }

        public string ToString(int tabQnt)
        {
            var sb = new StringBuilder();
            const string tab = @"    ";
            for (var i = 0; i < tabQnt; i++) sb.Append(tab);
            sb.Append("<ViewAttributes ");
            if (!string.IsNullOrEmpty(Scope))
                sb.AppendFormat(@"Scope=""{0}"" ", Scope);
            if (!string.IsNullOrEmpty(ModerationType))
                sb.AppendFormat(@"ModerationType=""{0}"" ", ModerationType);
            sb.Append(" />");
            return sb.ToString();
        }
    }
}
